/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2013-2014 sagyf Yang. The Four Group.
 */
define(['adminapp'], function ($app) {
    $app.navactive('gift_list');

    var action_tpl = Handlebars.compile($("#action_template").html());
    var tpl_picute = Handlebars.compile($("#pricute_template").html());

    $app.listtable({
        'sAjaxSource' : g.ctx + "admin/gift/gift/list",
        'bAutoWidth'  : true,
        'aoColumns'   : [
            $app.checkall,
            $app.autono,
            {'mDataProp': 'code' },
            {'mDataProp': 'name', "bSortable": false},
            {'mDataProp': 'cover', "bSortable": false},
            {'mDataProp': 'begin_time' },
            {'mDataProp': 'end_time' },
            {'mDataProp': 'stock' },
            {'mDataProp': 'intergral' },
            {'mDataProp': 'status' }
        ],
        'aoColumnDefs': [
            {
                'aTargets': [4],
                'mData'   : null,
                'mRender' : function (data, type, full) {
                    if (full['cover']) {
                        full['portfolio'] = full['cover'].replace('.', '.thumbnail.');
                    }
                    return tpl_picute(full);
                }
            },
            {
                'aTargets': [9],
                'mData'   : null,
                'mRender' : function (data, type, full) {
                    if (full['status'] == 1) {
                        return '进行中';
                    } else {
                        return '停用';
                    }
                }
            },
            {
                'aTargets': [10],
                'mData'   : null,
                'mRender' : function (data, type, full) {
                    return action_tpl(full);
                }
            }
        ]
    }, 'gift-list');

});
